package com.bw.mvvm.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;

import com.blankj.utilcode.util.LogUtils;
import com.bw.mvvm.BaseApplication;

import java.util.HashMap;
import java.util.Map;


//sp 存储token 取token
public class SpUtils {

    private static String name = "save";

    public static void writeToken(String value){

        SharedPreferences sharedPreferences = BaseApplication.getInstance().getSharedPreferences(name, Context.MODE_PRIVATE);
        sharedPreferences.edit().putString("token",value).commit();

    }
    public static String readToken(){
        SharedPreferences sharedPreferences = BaseApplication.getInstance().getSharedPreferences(name, Context.MODE_PRIVATE);
        return sharedPreferences.getString("token",null);
    }

    public static void setUser(String name){
        SharedPreferences sharedPreferences = BaseApplication.getInstance().getSharedPreferences("save", Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putString("name",name).commit();
    }
    public static String getUser(){
        SharedPreferences sharedPreferences = BaseApplication.getInstance().getSharedPreferences(name, Context.MODE_PRIVATE);
       return sharedPreferences.getString("name",null);
    }

    public static void setId(String id){
        SharedPreferences sharedPreferences = BaseApplication.getInstance().getSharedPreferences("save", Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putString("id",id).commit();
    }
    public static void setUserId(String userid){
        SharedPreferences sharedPreferences = BaseApplication.getInstance().getSharedPreferences("save", Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putString("userId",userid).commit();
    }
    public static String getId(){
        SharedPreferences sharedPreferences = BaseApplication.getInstance().getSharedPreferences(name, Context.MODE_PRIVATE);
        return sharedPreferences.getString("id",null);
    }
    public static String getUserId(){
        SharedPreferences sharedPreferences = BaseApplication.getInstance().getSharedPreferences(name, Context.MODE_PRIVATE);
        return sharedPreferences.getString("userId",null);
    }
}
